import java.util.Scanner;

class ListNode{
    int val;
    ListNode next;
    ListNode(int x){
        val = x;
        next = null;
    }
}

public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB){
        ListNode pl = headA;//先假设链表A是长的
        ListNode ps = headB;

        //求两个链表的长度
        int len1 = 0,len2 = 0;
        while(pl != null){
            len1++;
            pl = pl.next;
        }
        while(ps != null){
            len2++;
            ps = ps.next;
        }
        pl = headA;
        ps = headB;

        //求链表的长度差
        int len = len1 - len2;
        if(len < 0){
            pl = headB;
            ps = headA;
            len = len2-len1;
        }

        //让pl先走len步
        while(len != 0){
            pl = pl.next;
            len--;
        }

        //pl与ps同时走，知道相遇。
        while(pl != ps){
            pl = pl.next;
            ps = ps.next;
        }
        //如果没有公共节点，直接返回null
        if(pl == null){
            return null;
        }
        return pl;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int len1 = in.nextInt();
            ListNode dummy1 = new ListNode(0);
            ListNode tail1 = dummy1;
            for(int i = 0; i < len1; i++){
                int val = in.nextInt();
                tail1.next = new ListNode(val);
                tail1 = tail1.next;
            }
            int len2 = in.nextInt();
            ListNode dummy2 = new ListNode(0);
            ListNode tail2 = dummy2;
            for(int i = 0; i < len2; i++){
                int val = in.nextInt();
                tail2.next = new ListNode(val);
                tail2 = tail2.next;
            }
            int commonLen = in.nextInt(); // 读取公共部分的长度
            for(int i = 0; i < commonLen; i++){
                int val = in.nextInt();
                tail1.next = new ListNode(val);
                tail1 = tail1.next;
                tail2.next = tail1; // 使两个链表有公共部分
                tail2 = tail2.next;
            }
            Solution solution = new Solution();
            ListNode result = solution.getIntersectionNode(dummy1.next,dummy2.next);
            if(result != null){
                System.out.println(result.val);
            }else{
                System.out.println("两个链表没有相交");
            }
        }

    }
}
